package com.ican.oc.dao;

import org.springframework.stereotype.Repository;

import com.ican.oc.common.hibernate.OcHibernateDao;
import com.ican.oc.domain.OcCategoryDescription;

@Repository("ocCategoryDescriptionDao")
public class OcCategoryDescriptionDao extends OcHibernateDao<OcCategoryDescription, Integer> {

    public OcCategoryDescription findOcCateDescByCateIdAndLang(Integer categoryId, Integer languageId) {
        String hql = "from OcCategoryDescription where pk.categoryId = " + categoryId + " and pk.languageId = " + languageId;
        return this.findUnique(hql);
    }
    
    public void updateOcCateDesc(Integer categoryId, Integer languageId, String name, String description){
        String hql = "update OcCategoryDescription set name = ?";
        Object[] params = new Object[]{name};
        if(description != null){
            hql = hql + ", description = ?";
            params = new Object[]{name, description};
        }
        hql = hql + " where pk.categoryId = " + categoryId + " and pk.languageId = " + languageId;
        this.batchExecute(hql, params);
    }
}
